<template>
    <div>
<h2>房价列表</h2>
<input type="button" value="添加" class="btn btn-info" @click="Add">
<div>
<span>类型名称:</span>
<input type="text" v-model="model.TypeName">
<input type="button" value="查询" class="btn btn-success" @click="GetList">
</div>
<table class="table">
 <tbody>
    <tr class="bg-primary">
        <td>房型名称</td>
        <td>价格</td>
        <td>房价名称</td>
        <td>房量数量</td>
        <td>早餐数量</td>
        <td>人数数量</td>
        <td>开始时间</td>
        <td>结束时间</td>
        <td>门店名称</td>
        <td>房价计划图标</td>
        <td>房价计划状态</td>
        <td>操作</td>
    </tr>


    <tr v-for="item  in list" :key="item.Id">
        <td>{{item.TypeName}}</td>
        <td>￥{{item.Price}}元</td>
        <td>{{item.Name}}</td>
        <td>{{item.HouseNumber}}</td>
        <td>{{item.BreakfastNumber}}份</td>
        <td>{{item.PersonNumber}}人</td>
        <td>{{item.BenginTime.substring(0,10)}}</td>
        <td>{{item.EenTime.substring(0,10)}}</td>
        <td>{{item.ShopName}}</td>
        <td><img :src="item.Photo" width="100" height="100"> </td>
        <td>{{item.State?"上架":"下架"}}</td>
        <td>
            <input type="button" value="删除" class="btn btn-danger" @click="housedel(item.Id)">
            <input type="button" value="编辑" class="btn btn-success" @click="houseupd(item.Id)">
            <input type="button" value="下架"  v-if="item.State==1" class="btn btn-info" @click="houstate(item.Id,item.State)">
            <input type="button" value="上架"  v-if="item.State==0" class="btn btn-info" @click="houstate(item.Id,item.State)">
    
        
        </td>
    </tr>
 </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import { useRouter ,useRoute} from 'vue-router';
const router=useRouter();
const  route=useRoute();

//跳转添加
const Add=()=>{
router.push('/housePriceAdd')
}



//传数据
let list:any=ref([]);

const model=reactive({
TypeName:'',
})


onMounted(()=>{
 GetList();

})

//显示
const GetList=()=>{

axios({
url:'https://localhost:7291/api/HousePrice/HousePriceList',
method:'get',
params:model,
})

.then((res)=>{
console.log(res);
list.value=res.data;
})


.catch((ree)=>{
console.log(ree);
})

}




//删除
const housedel=(Id:any)=>{

var f=(confirm('确定要删除吗?'))

if(f){

axios({
url:'https://localhost:7291/api/HousePrice/HousePriceDel',
method:'delete',
params:{
    Id:Id,
}

})

.then((res)=>{
console.log(res);
list.value=res.data;

if(res.data>0){
alert('删除成功');
GetList();
return;

}
else{
alert('删除失败');
return;
}
})



.catch((ree)=>{
console.log(ree);
})


}

}



//修改状态
const houstate=(Id:any,State:any)=>{
if(State==1){
    State=0;
}
else{
    State=1;
}


axios({
url:'/api/HousePrice/HousePriceState',
method:'put',
params:{
    Id:Id,
    State:State,
}

})
.then((res)=>{
console.log(res);
list.value=res.data;

if(res.data>0){
alert('成功');
GetList();
return;

}
else{
alert('失败');
return;
}
})


.catch((ree)=>{
console.log(ree);
})


}
   

//修改页面
const houseupd=(Id:any)=>{
router.push({
path:'/housePriceUpd',
query:{
    Id:Id,
}
})
}




</script>

<style scoped>

</style>